#!/usr/bin/perl 
# fichier d'entrée
$filename = "debcand.txt";
open(FILEIN, $filename);
#preparer la sortie html
open(OUT,">sortie.html");
print OUT "<html><body style=\"color:white;\" bgcolor=\"black\">\n";
print OUT "<center><h2 style=\"color:yellow\">Analyse de fichier debcand.txt</h2><center>\n";
$nbre_lignes=0;
$nbre_mots=0;
$mots_diff=0;
$contenu="";
while (my $ligne=<FILEIN>)
{
  $ligne=~ s/\./ /g;
  $ligne=~ s/,/ /g;
  $ligne=~ s/;/ /g;
  $ligne=~ s/:/ /g;
  $ligne=~ s/--/ /g;
  $ligne=~ s/-/ /g;
  $ligne=~ s/\(/ /g;
  $ligne=~ s/\)/ /g;
  $ligne=~ s/!/ /g;
  $ligne=~ s/'/\' /g;
  @tab_mot = split(/ /,$ligne);
  for (my $k=0; $k<=$#tab_mot-1; $k++)
  {
      if($tab_mot[$k] ne "")
      {
	push(@tab_mots, $tab_mot[$k]);
	if(!($contenu=~$tab_mot[$k]))
	{
	  $contenu.=" ".$tab_mot[$k];
	  $mots_diff+=1;
	}
      }
   }
    $nbre_lignes+=1;
}
$nbre_mots = $#tab_mots;

print OUT "<p> $nbre_lignes ligne(s), $nbre_mots mot(s) dont $mots_diff mot(s) diff&eacute;rent(s).</p>";
print OUT "<br/><br/>";
print OUT "<center><table bgcolor=\"black\" border=1 style=\"border-color:green;\" >";
print OUT "<tr><td style=\"color:red;\">Mots</td><td style=\"color:red;\">nombre des occurrences</td></tr>";
$contenu="";
  for (my $i=0; $i<=$#tab_mots-1; $i++)
  {
    my $nbr_redondance=1;
    if(!($contenu=~$tab_mots[$i]))
    {
      $contenu.=$tab_mots[$i];
      for (my $j=0; $j<=$#tab_mots-1; $j++)
      {  
	  if($i!=$j)
	  {
	      if ($tab_mots[$i] eq $tab_mots[$j])
	      {
		$nbr_redondance+=1;
	      }
	  }
      }
      print OUT "<tr><td style=\"color:white;\">$tab_mots[$i]</td><td style=\"color:white;\">$nbr_redondance</td></tr>";
    }
  }
print OUT "</table></center>";
print OUT "</body></html>";
close(FILE);
close(OUT);